package cxydmmszl.chapter08.t134;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * <li style="color: red;">Prob</li>
 * 打印 N 个数组整体最大的 Top K
 * <li style="color: red;">Desc</li>
 *
 * <li style="color: red;">Link</li> CD34
 *
 * @author habitplus
 * @since 2021-09-06 14:50
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String[] ss = bf.readLine().split(" ");
        int t = Integer.parseInt(ss[0]);
        int k = Integer.parseInt(ss[1]);
        int[][] arr = new int[t][];
        int n;

        for (int i = 0; i < t; i++) {
            ss = bf.readLine().split(" ");
            n = Integer.parseInt(ss[0]);
            arr[i] = new int[n];
            for (int j = 0; j < n; j++) {
                arr[i][j] = Integer.parseInt(ss[j + 1]);
            }
        }
        bf.close();

        printTopK(arr, k);
    }

    private static void printTopK(int[][] matrix, int k) {
        if (matrix == null || matrix.length == 0 || k < 1) {
            System.out.println();
            return;
        }

        int n = matrix.length;
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            if (matrix[i] == null || matrix[i].length == 0) {
                p[i] = -1;
            } else {
                p[i] = matrix[i].length - 1;
            }
        }

        StringBuilder sb = new StringBuilder();
        int curMax, r;
        for (int i = 0; i < k; i++) {
            r = -1;
            curMax = Integer.MIN_VALUE;
            for (int j = 0; j < n; j++) {
                if (p[j] != -1 && matrix[j][p[j]] > curMax) {
                    r = j;
                    curMax = matrix[j][p[j]];
                }
            }

            if (r == -1) break;
            sb.append(matrix[r][p[r]]).append(" ");
            p[r]--;
        }

        System.out.println(sb.toString());
    }
}
